let baseURL = 'https://exam.youmengxinxi.com:10021'
$(function () {
//jq_start
//    ajax_start
    authorities = $.session.get('authorities');
    let userName = $.session.get('userName');
    let password = $.session.get('password');
    let school_name = $.session.get('school_name');
    let user_name = $.session.get('user_name');
    $("#bk_school_name").text(school_name)
    $("#bk_user_name").text(userName)
//ajax_end

    //    登陆状态监测 start
    setTimeout(js, 100)

    function js() { }

        let login = $.session.get('log_type');
        if (login != 1) {
            alert("请先登录");
            location.href = "login.html";
        } else if (login == 1) {
            $("#is_login").removeClass('hide');
            $("#is_login").show();
            $("#not_login").addClass('hide');
        }


    //    登陆状态监测 end
//    退出登录start
    $('#out_login_user').click(function () {
        $.session.clear();
    })
//退出登录end


//jq_end
})
//jQ start 左侧列表部分
$(function () {
    //ajax start 请求用户菜单权限
    $.ajax({
        url: baseURL + '/admin/api/permission/permissionRoleList',
        type: 'post',
        dataType: 'json',
        headers: {'authorities': authorities},
        data: {},
        success: function (e) {
            //if 判断 start
            if(e.code == 1){
                let yy = e.content[0];
                //for i 循环 start
                for (let i = 0; i < yy.length; i++) {
                    //if 判断 start
                    yys = yy[i].nodes ? yy[i].nodes : null
                    //判断是否存在nodes 不存在就添加null
                    //如果为null 就不执行
                    if (yys !== null) {
                        //for u 循环 start
                        for (let u = 0; u < yys.length; u++) {
                            let lj = yys[u].url;
                            let ljj = lj.split(".");
                            let ljjj = ljj[0]
                            //获取url 把html部分去掉 赋值给id
                            $("#pager_group").append(
                                '<div class="list-group-item" id="' + ljjj + '">' + yys[u].text + '</div>'
                            );
                        }

                    }
                }
            }
            else{
                alert("请求失败")
            }

        },
        error:function(){
            alert("请重新登陆",location.href = "login.html")
        }
    })
//    暂存
//     let lj = page_name[u].url;
//     let ljj = lj.split(".");
//     let ljjj = ljj[0]


//判断点击侧栏目录
    $("#pager_group").on("click", ".list-group-item", function () {
        $(this).addClass("active")
        let hf = $(this).attr("id")

        location.href = "" + hf + ".html";
    });

    //获取页面名
    function pageName() {
        var a = location.href;
        var b = a.split("/");
        var c = b.slice(b.length - 1, b.length).toString(String).split(".");
        return c.slice(0, 1);
    }
})

//find_arr方法 arr目标数组 key等于val时 返回target_key
function find_arr(arr, key, val, target_key) {
    //for i 循环 start
    for (let i = 0; i < arr.length; i++) {
        //if 判断 start
        if (arr[i][key] == val) {
            return arr[i][target_key]
        }
    }
    return -1
}


